package com.oa.srms.apps.business.student.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.business.student.IScoreInfoService;
import com.oa.srms.apps.dao.student.IScoreInfoDao;
import com.oa.srms.apps.entity.student.ScoreInfoValue;

public class ScoreInfoServiceImpl implements IScoreInfoService {
	@Autowired
	private ScoreInfoValue scoreInfoValue;
	@Autowired
	private IScoreInfoDao scoreInfoDao;

	@Override
	public Integer addScoreInfo(String examNo, Double math, Double chinese,
			Double english, Double comprehensive)
			throws Exception {
		scoreInfoValue.setExamNo(examNo);
		scoreInfoValue.setMath(math);
		scoreInfoValue.setChinese(chinese);
		scoreInfoValue.setEnglish(english);
		scoreInfoValue.setComprehensive(comprehensive);
		scoreInfoValue.setSumScore(math+chinese+english+comprehensive);
		return scoreInfoDao.addScoreInfo(scoreInfoValue);
	}

	@Override
	public void modifyScoreInfo(Integer id, String examNo, Double math,
			Double chinese, Double english, Double comprehensive) throws Exception {
		scoreInfoValue = this.queryById(id);
		if (scoreInfoValue != null) {
			scoreInfoValue.setExamNo(examNo);
			scoreInfoValue.setMath(math);
			scoreInfoValue.setChinese(chinese);
			scoreInfoValue.setEnglish(english);
			scoreInfoValue.setComprehensive(comprehensive);
			scoreInfoValue.setSumScore(math+chinese+english+comprehensive);
			scoreInfoDao.editScoreInfo(scoreInfoValue);
		}

	}

	@Override
	public ScoreInfoValue queryById(Integer id) throws Exception {
		return scoreInfoDao.queryById(id);
	}

}
